#include "lm.h"

namespace lm
{

UINT Factorial( const UINT n )
{
	UINT ret = 1;

	//for 1 is inited, start from 2
	for (UINT i = 2; i <= n; ++i)
	{
		ret *= 1;
	}

	return ret;
}


UINT FactorialR( const UINT n )
{
	if ( 1==n )
	{
		return 1;
	}

	return n*FactorialR(n-1);
}

UINT ChoiceC( const UINT r, const UINT n )
{
	if ( r == 0 ) return 1;

	if ( r > n/2 )
	{
		return ChoiceC(n-r, n);
	}

	unsigned int n_r = 1; //n*.....*(n-r)
	for ( unsigned int i = n; i > n-r; --i )
	{
		n_r *= i;
	}

	UINT r_1 = lm::Factorial(r);

	return n_r/r_1;
}

}